<script type="text/javascript">
    var base_url = "{{""|base_url}}",edialog,ndialog;
    var RecaptchaOptions = {
        theme : 'custom',
        custom_theme_widget: 'recaptcha_widget'
    };
    $(document).ready(function () {
		uiMessage(Math.random());
        edialog=new bckdialog({type:'error'});
        ndialog=new bckdialog();
        islc({
            element:'#_sgn_month',minwidth:'158px',
            title:'Chọn tháng',biz:true
        });
        islc({
            element:'#_sgn_qst',menuwidth:'auto',minwidth:'320px',
            title:'Chọn câu hỏi bảo mật',
            style :{'margin-top':'-320px'}
        });
        islc({
            element:'#_lang',
            header:true,
            title:'Chọn ngôn ngữ',
            height:'224px',filter:true
        });
        islc({
            element:'#_mul_contr',
            header:true,aclass:'_mul',
            title:'Chọn quốc gia',
            height:'224px',filter:true
        });
        islc({
            element:'#_sgn_type',aclass:'_mul',
            multi:false,header:false,biz:true,
            title:'Chọn mạng xã hội'
        });
        //ShowDialogMessage($("#reg-box-step-3"));return;
        $("#reg-box-step-1 ._overflow").fadeOut(2000);
        $('#_password').keyup(function(){
            var passstreng=checkStrength($(this).val());
            if ( $('#passwdRating').html()==passstreng ) return;
            $('#passwdRating').html(passstreng);
            if(passstreng==="Weak"){
                $("#strength-bar").stop().animate({width:'20%',backgroundColor:'#ff0000'},500);
            }else if(passstreng==="Fair"){
                $("#strength-bar").stop().animate({width:'40%',backgroundColor:'#F1B75F'},500);
            }else if(passstreng==="Good"){
                $("#strength-bar").stop().animate({width:'60%',backgroundColor:'#3380CB'},500);
            }else if(passstreng==="Strong"){
                $("#strength-bar").stop().animate({width:'80%',backgroundColor:'#33CB80'},500);
            }else if(passstreng==="Verry Strong"){
                $("#strength-bar").stop().animate({width:'100%',backgroundColor:'#33CB80'},500);
            }else{
                $("#strength-bar").stop().animate({width:'2px',backgroundColor:'#ff0000'},500);
            }
        })
                
    {{if isset($smarty.get.popvalid)}}
            $("#_frm").validationEngine({isPopup:true});
    {{else}}
            $("#_frm").validationEngine({isPopup:false});
    {{/if}}
        $("#step-2-back").click(function(){
            $("#reg-box-step-1 .tranf-w-50").addClass("d-p-n");
            $("#reg-box-step-2").addClass("d-p-n");
            $("#reg-box-step-2 ._overflow").show();
            //$("#frm-step-2").validationEngine();
        });
        $("#reg-box-step-2").addClass("d-p-n");
        $("#step-1-next").click(_sm_reg);
        $("#step-2-next").click(step3);
        addEditorContent('_tcontent',$(window).height()-26);
        $("#_toogle_editor").click(function(){
            $("#_editor_box").toggle();
        });
    });
    function _sm_reg(){
        try{
            var valid=true;
            $("#reg-box-step-1 select").each(function(){
                var cls="";
                if($(this).attr("multiple")=="true") cls="_mul";
                if($(this).show().validationEngine('validate')){
                    $(this).multiselect("option",{classes:cls+" erb"});
                    valid = false;
                }else{
                    $(this).multiselect("option",{classes:cls});
                }
                $(this).hide();
            })
            if($("#recaptcha_response_field").val()==""){
                $("#recaptcha_response_field").addClass("erb");
                $(".erc",$("#recaptcha_response_field").parents("#recaptcha_widget"))
                .html("The characters you entered didn't match the word verification. Please try again.");
                valid = false;
            }else{
                $("#recaptcha_response_field").removeClass("erb");
                $(".erc",$("#recaptcha_response_field").parents("#recaptcha_widget")).html("");
            }
            if($('#_frm').validationEngine('validate') && valid){
                $("#reg-box-step-1 .tranf-w-50.d-p-n").removeClass("d-p-n");
                $("#reg-box-step-2").removeClass("d-p-n");
                islc({
                    element:'#_mul_st',num:2,minwidth:'320px',
                    multi:true,aclass:'_mul'
                });
                $("#reg-box-step-2 ._overflow").fadeOut(2000);
                $("#frm-step-2").validationEngine();
                return false;
            }else{
                //alert("false");
                return false;
            }
        }catch(e){
            console.log(e.message);
            return false;
        }
    }
    function step3(){
        
        $("#reg-box-step-3").show();
        $("#reg-box-step-3 .i-l-d").show();
        islc({
            element:'#_mul_position',num:2,minwidth:'320px',height:'240px',
            multi:false,aclass:'_mul',style :{'margin-top':'-120px'},
            title:'Chọn danh mục cha'
        });
        $("#reg-box-step-3 .i-l-d").fadeOut(2000);//.addClass("d-p-n");
        $("#frm-step-3").validationEngine();
        //console.log(0);
        ShowDialogMessage($("#reg-box-step-3"),"Categorys");
    }
    function cat(_cat){
        $("#reg-box-step-3").show();
        $("#reg-box-step-3 .i-l-d")
            .removeClass("b-g-c-w-50")
            .show();
        var dig=new bckdialog({
            title:'Categorys',
            icon:'<img class="p-a t-4 l-4 w-24 h-24" src="{{base_url()}}libraries/images/80/edit.png"/>',
            message:$("#reg-box-step-3")
        }).open();
        $("#reg-box-step-3 .content-biz").load(
            "{{base_url()}}widgets/cateditor/"+_cat,
            function(){
                islc({
                    element:'#_categories',num:2,minwidth:'320px',height:'240px',
                    multi:false,aclass:'_mul',style :{'margin-top':'-120px'},
                    title:'Chọn danh mục cha',filter:true
                });
                islc({
                    element:'#cat_type',minwidth:'158px',
                    multi:false,biz:true
                });
                islc({
                    element:'#cat_status',minwidth:'158px',
                    multi:false,biz:true
                });
                $("#reg-box-step-3 .i-l-d").fadeOut(2000);
                $("#frm-step-3").validationEngine();
            }
        );
    }
    function AliasTo(from,element){
		if($(from).val()==$(from+'c').val())return;
        var url="{{"widgets/getalias"|base_url}}";
        var data={text:$(from).val()};
        var proc=new backend({
            url:url,data:data,
            callback:function(rsdata){
                if(rsdata.result===1){
                    $(element).val(rsdata.alias);
                }else{
                    edialog.open(rsdata.message);
                }
            }
        }).call();
    }
    function ucategory(){
        var valid=true;
        $("#frm-step-3 select").each(function(){
            var cls="";
            if($(this).attr("multiple")==="true") cls="_mul";
            if($(this).show().validationEngine('validate')){
                $(this).multiselect("option",{classes:cls+" erb"});
                valid = false;
            }else{
                $(this).multiselect("option",{classes:cls});
            }
            $(this).hide();
        })
        if( $('#frm-step-3').validationEngine('validate') === false || valid===false)return false;
        new backend({
            url         :   "{{"backend/category/update"|base_url}}",
            data        :   {
                cat_id      :   $("#cat_id").val(),
                title       :   $("#_title").val(),
                alias       :   $("#_alias").val(),
                categories  :   $("#_categories").val(),
                position    :   $("#cat_position").val(),
                status      :   $("#cat_status").val(),
                type        :   $("#cat_type").val()
            },
            datatype    :   "json",
            proc_start  :   proc_sart("#reg-box-step-3"),
            proc_end    :   proc_end("#reg-box-step-3"),
            callback    :   function(data){
                if(data.result<0){
					edialog.open(data.message);
                }else{
                    uiMessage(data.message);
                }
            }
        }).call();
        return false;
    }
</script>